local duanhuo = fk.CreateSkill{
  name = "xiaobai__duanhuo",
}

Fk:loadTranslationTable{
  ["xiaobai__duanhuo"] = "断祸",
  [":xiaobai__duanhuo"] = "出牌阶段限一次，你可以获得一名其他角色所有手牌并交给其等量手牌，然后其可以横置自己。",
  ["#xiaobai__duanhuo"] = "断祸：获得一名其他角色所有手牌并交给其等量手牌，然后其可以横置武将牌",
  ["#xiaobai__duanhuo-give"] = "断祸：请交给 %dest %arg张手牌",
  ["#xiaobai__duanhuo-ask"] = "断祸：是否横置你的武将牌？",

  ["$xiaobai__duanhuo1"] = "君偏见一时利害，忘究始终也。",
  ["$xiaobai__duanhuo2"] = "法天运者，福祸有常，取舍无定。",
}

duanhuo:addEffect("active", {
  anim_type = "control",
  prompt = "#xiaobai__duanhuo",
  card_num = 0,
  target_num = 1,
  times = function (self, player)
    return player.phase == Player.Play and 1 - player:usedSkillTimes(duanhuo.name, Player.HistoryPhase) or -1
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(duanhuo.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local n = target:getHandcardNum()
    room:moveCardTo(target:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, duanhuo.name, nil, false, player)
    if player.dead or target.dead or player:isKongcheng() then return end
    local cards = room:askToCards(player, {
      min_num = n, 
      max_num = n, 
      include_equip = false,
      skill_name = duanhuo.name,
      cancelable = false, 
      prompt = "#xiaobai__duanhuo-give::"..target.id..":"..n})
    room:moveCardTo(cards, Card.PlayerHand, target, fk.ReasonGive, duanhuo.name, nil, false, player)
    if not target.dead and not target.chained and room:askToSkillInvoke(target, {skill_name = duanhuo.name, prompt = "#xiaobai__duanhuo-ask"}) then
      target:setChainState(true)
    end
  end
})

return duanhuo